package com.haiqi.config.webmagic;

import us.codecraft.webmagic.Page;
import us.codecraft.webmagic.Site;
import us.codecraft.webmagic.Spider;
import us.codecraft.webmagic.processor.PageProcessor;
import us.codecraft.webmagic.selector.Selectable;

import java.util.List;

/**
 * Created by hythzx on 2016/8/12.
 */
public class FilmContentSpider implements PageProcessor {

    private Site site = Site.me().setRetryTimes(3).setSleepTime(100);

    @Override
    public void process(Page page) {
        Selectable xpath = page.getHtml().xpath("//div[@class='ndownlist']");
        for (Selectable selectable : xpath.nodes()) {
            Selectable xpath1 = selectable.xpath("//script");
            System.out.println(selectable);
        }
        List<String> all = xpath.all();
        System.out.println(all);
    }

    @Override
    public Site getSite() {
        return site;
    }

    public static void main(String[] args) {
        Spider.create(new FilmContentSpider()).addUrl("http://www.xiamp4.com/Html/GP23662.html").thread(5).run();
    }
}
